﻿using KC.Service.Core.DTO.Dict;
using KC.Enums.Admin;
using KC.Framework.Tenant;
using KC.Service.Core.EFService;
using KC.DTO.Admin;
using KC.DTO.Core;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace KC.Service.Admin
{
    public interface ITenantUserService 
    {
        #region TenantUsers

        bool ExistTenantName(string tenantName);

        List<TenantUserDTO> GetAllTenantUsers();
        List<TenantUserDTO> GetAllSingleTenantUsers();
        List<TenantUserDTO> GetAllNeedInitDbTenantUsers();
        List<TenantUserDTO> GetSingleTenantUsersByNames(List<string> tenantNames);
        List<TenantUserDTO> GetTenantUsersDetailByNames(List<string> tenantNames);

        PaginatedBaseDTO<TenantSimpleDTO> GetTenantUsersByFilter(int pageIndex, int pageSize, int? cloudType, int? version,
            string code, string contact, string userName);
        PaginatedBaseDTO<TenantSimpleDTO> GetTenantUsersByOpenAppId(int pageIndex, int pageSize, Guid applicationId,
            string tenantDisplayName, List<string> exceptTenants = null, bool isShowExceptTenants = false);
        PaginatedBaseDTO<TenantSimpleDTO> GetTenantUsers(int pageIndex, int pageSize,
            string tenantDisplayName, string providerTenantName = null, TenantType? tally = null);
        //PaginatedBaseDTO<TenantSimpleDTO> GetTenantUsers(int pageIndex, int pageSize,
        //    string tenantDisplayName, TenantType tally, string providerTenantName);

        PaginatedBaseDTO<TenantSimpleDTO> GetTenantUsersByPredicate(int pageIndex, int pageSize, List<string> execptTenants, string tenantName, string tenantDisplayName);

        TenantUserDTO GetTenantUserById(int id);
        TenantUserDTO GetTenantUserDetailById(int id);
        //[CachingCallHandler(TimeOutConstants.CacheTimeOut, Order = 0)]
        TenantUserDTO GetTenantUserByName(string tenantName);
        TenantUserDTO GetTenantUserByNameUnCache(string tenantName);
        TenantUserDTO GetTenantUserByPenAppId(Guid applicationId, string tenantName);

        bool SaveTenantUser(TenantUserDTO model);
        bool UpdateTenantUserPwdHash(List<TenantUserDTO> models);
        bool UpdateTenantUserContactPhone(TenantUserDTO model);
        bool UpdateTenantUserContactEmail(TenantUserDTO model);
        bool RepeatContactPhone(string phone);
        bool RepeatContactEmail(string email);
        bool SoftRemoveTenantUser(List<int> ids);
        bool RemoveTenantUserByNames(List<string> tenantNames);
        bool SoftRemoveTenantUserByNames(List<string> tenantNames);

        bool AddTenantUserApplications(int tenantId, List<Guid> applicationIds);

        List<string> LoadTenantName(string tenantName);

        #endregion

        #region Tenant

        //[CachingCallHandler(TimeOutConstants.DefaultCacheTimeOut, 0, Order = 0)]
        Tenant GetTenantByName(string tenantName);
        Task<Tenant> GetTenantUserByNameAsync(string tenantName);
        //[CachingCallHandler(TimeOutConstants.DefaultCacheTimeOut, 0, Order = 0)]
        Task<Tenant> GetTenantByNameOrNickNameAsync(string tenantName);

        //[CachingCallHandler(TimeOutConstants.DefaultCacheTimeOut, 0, Order = 0)]
        Task<Tenant> GetTenantEndWithDomainName(string domainName);
        Tenant GetTenantByAppIdWithName(Guid appId, string tenantName);

        List<Tenant> GetInitalTenants();
        IEnumerable<Tenant> GetTenantsByNames(List<string> tenantNames);
        List<Tenant> GetOpenAppTenantsByNames(Guid appId, List<string> tenantNames);
        List<Tenant> GetAllOpenAppTenants(Guid appId);

        List<JsonDictionaryDTO> QueryTenantByKey(string key);

        string GetTenantDisplayNameByName(string name);

        bool SetNickName(int tenantId, string nickName);

        #endregion

        #region Tenant's Application && Init Tenant's Database & Web Server

        TenantUserApplicationDTO GetDetailApplicationWithModelsByTenantIdAndAppId(int tenantId, Guid appId);
        TenantUserApplicationDTO GetTenantApplicationByFilter(int tenantId, Guid appId);
        List<TenantUserApplicationDTO> GetTenantApplicationsByTenantName(string tenantName);
        List<TenantUserApplicationDTO> GetTenantApplicationsByTenantId(int tenantId);

        List<Guid> GetTenantApplicationIdsByTenantId(int tenantId);
        string SetInitTenantsDbJobAppsStatus();
        bool UpTenantDisplayName(string tenantName, string displayName);
        bool GeneratDataBaseAndOpenWebServer(int tenantId, string appId);
        string RollBackTenantDataBase(int tenantId, string appId);

        List<string> UpgradeTenantDatabaseByIds(List<int> ids);
        List<string> UpgradeAllTenantDatabase();
        List<string> RollBackAllTenantDatabase();

        string UpgradeTenantDatabase(int tenantId, bool isUpdateStatus = true, bool isNewDatabase = true);
        string RollBackTenantDataBase(int tenantId);

        bool SendTenantAppOpenEmail(TenantUserDTO data);
        void AddOpenAppErrorLog(int tenantId, string tenantDisplayName, OpenServerType type, string error);
        List<ApplicationStatus> GetStateByTenantNameAndAppId(string tenantName, Guid applicationId);

        List<TenantSimpleDTO> GetTenantUserByDatabasePoolId(int databaseId);
        List<TenantSimpleDTO> GetTenantUserByStoragePoolId(int storagePoolId);

        #endregion

        #region Tenant's Sms & Email & CallCenter Service
        string OpenEmailService(int tenantId, string tenantName);
        string OpenSmsService(int tenantId, string tenantName);
        string OpenCallCenterService(int tenantId, string tenantName);
        #endregion

        #region 平台Tenant推送接口

        bool SaveSendTenantUsers(List<SendTenantUserDTO> models);

        bool SaveSendTenantUser(SendTenantUserDTO model);

        bool UpdateTenantUserInfo(SendTenantUserDTO model);

        bool SentUserVersion(SendTenantUserDTO model);
        #endregion

        #region TenantUserOpenAppErrorLog

        PaginatedBaseDTO<TenantUserOpenAppErrorLogDTO> GetOpenAppErrorLogsByFilter(int pageIndex, int pageSize,
            string tenantDisplayName, int? openServerType, string order);
        TenantUserOpenAppErrorLogDTO GetTenantErrorlogFormByProcessLogId(int id);

        bool UpdateTenantErrorLogStatus(int id);
        #endregion

        #region TenantUserOperationLog
        PaginatedBaseDTO<TenantUserOperationLogDTO> GetTenantUserOperationLogByFilter(int pageIndex, int pageSize, string searchTenantDisplayName, string searchTenantName, string order, int? operationLogType);

        bool AddTenantOperationLog(TenantUserOperationLogDTO model);
        #endregion

    }
}
